﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Kitware.VTK;

namespace HAVTKPack
{
    public class CylinderGeometry:Geometry
    {
        public CylinderGeometry()
        {
 
        }

        public CylinderGeometry(double r,double h)
        {
            this._radius = r;
            this._height = h;
 
        }


        double _radius=2;//圆半径

        /// <summary>
        /// 圆柱体的半径
        /// </summary>
        public double Radius
        {
            get { return _radius; }
            set {

                if (this._radius !=value)
                {
                    _radius = value;


                    this.OnSetRadius();
                    
                }
                
            
            }
        }


        protected void OnSetRadius()
        {
            if (this.ParentNode==null)
            {
                return;
                
            }

            if (this.ParentNode.Scene==null)
            {
                return;
                
            }

            if (this.ParentNode.Scene.IsRendering)
            {
                this.cylinder.SetRadius(this._radius);

            }
 
        }
        double _height=4;//自身高度

        /// <summary>
        /// 高度
        /// </summary>
        public double Height
        {
            get { return _height; }
            set {

                if (this._height!=value)
                {
                    this._height = value;

                    this.OnSetHeight();
                }
               
            
            
            }
        }
        protected void OnSetHeight()
        {
            if (this.ParentNode == null)
            {
                return;

            }

            if (this.ParentNode.Scene == null)
            {
                return;

            }

            if (this.ParentNode.Scene.IsRendering)
            {
                this.cylinder.SetHeight(this._height);

            }
        }

        int _resolution=12;


        public int Resolution
        {
            get { return _resolution; }
            set {

                if (this._resolution!=value)
                {
                    this._resolution = value;

                    this.OnSetResolution();
                    
                }
                
            
            }
        }
        protected void OnSetResolution()
        {
            if (this.ParentNode == null)
            {
                return;

            }

            if (this.ParentNode.Scene == null)
            {
                return;

            }

            if (this.ParentNode.Scene.IsRendering)
            {
                this.cylinder.SetResolution(this._resolution);

            }
        }

         [NonSerialized]
        vtkCylinderSource cylinder;

        public override void Render()
        {
            cylinder = vtkCylinderSource.New();
            cylinder.SetHeight(this._height);
            cylinder.SetRadius(this._radius);
            cylinder.SetResolution(this._resolution);

            //cylinder.SetCenter(0, cy.height / 2, 0);
            //cylinder.SetCenter(0, 0, 0);

            this._outPutData = cylinder.GetOutput();
            
            
        }

        public override void StopRender()
        {
            if (cylinder!=null)
            {
                cylinder.Dispose();
                
            }
           

           
        }

    }
}
